﻿@using Apps.Web.Core;
@using Apps.Web;
@using Apps.Common;
@using Apps.Models.Sys;
@using Apps.Locale;
@{
    ViewBag.Title = "入厂采样样品信息";
    Layout = "~/Views/Shared/_Index_Layout.cshtml";
    List<permModel> perm = null;
}

<table style="width:100%">
    <tbody>
        <tr>
            <td style="width:100%;vertical-align: top" colspan="2">
                <div class="mvctool">
                    <input id="BATCH_CODE" type="text" class="searchText" style="width:150px" placeholder="批次编码" />
                    <select class="easyui-combobox" name="MATERIEL_ID" id="MATERIEL_ID" style="width:200px;"></select>
                    <input id="SAMPLING_BEGIN_TIME" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd', maxDate: '#F{$dp.$D(\'SAMPLING_END_TIME\')}' })" type="text" class="searchText" style="width:150px" placeholder="最后时间起" />
                    <input id="SAMPLING_END_TIME" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd', minDate: '#F{$dp.$D(\'SAMPLING_BEGIN_TIME\')}' })" type="text" class="searchText" style="width:150px" placeholder="最后时间止" />
                    @Html.ToolButton("btnQuery", "fa fa-search", Resource.Query, ref perm, "Query", true)
                    @Html.ToolButton("btnExport", "fa fa-level-up", Resource.Export, ref perm, "Export", true)
                </div>
                <div>
                    <table id="List"></table>
                </div>
            </td>
        </tr>
</tbody>
</table>

<script type="text/javascript">
    $(function () {
          GetTranSuppList(2, "@ViewBag.MATERIEL_ID");
        $('#List').datagrid({
            url: '@Url.Action("GetList")',
            width:SetGridWidthSub(10),
            methord: 'post',
            height: SetGridHeightSub(40),
            fitColumns: true,
            sortName: 'SAMPLING_END_TIME',
            sortOrder: 'desc',
            idField: 'BATCH_CODE',
            pageSize: 15,
            pageList: [15, 20, 30, 40, 50],
            pagination: true,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            rownumbers: true,//行号
            onLoadSuccess: function (data) {
                @foreach(var r in perm){ if (r.Category == 2) { @Html.Raw("$(this).datagrid('hideColumn','" + r.KeyCode + "'); "); } }
            },
            columns: [[
                { field: 'BATCH_CODE', title: '批次编码', width: 80, sortable: true },
                { field: 'SAMPLE_PAIL', title: '样桶号', width: 80 },
                { field: 'MATERIEL_NAME', title: '物料', width: 140 },
                { field: 'SUPPLIER_NAME', title: '供应商名称', width: 140 },
                { field: 'SAMPLING_NODE_NAME', title: '采样机', width: 80, sortable: true },
                { field: 'SAMPLE_CODE', title: '样桶RFID', width: 80, sortable: true },
                { field: 'SAMPLING_END_TIME', title: '最后时间', width: 80, sortable: true },
                { field: 'SCount', title: '车数', width: 80, sortable: true }
            ]]
        });

        $("#btnQuery").click(function () {
            var BATCH_CODE = $("#BATCH_CODE").val();
            var SAMPLING_BEGIN_TIME = $("#SAMPLING_BEGIN_TIME").val();
            var SAMPLING_END_TIME = $("#SAMPLING_END_TIME").val();
            var MATERIEL_NAME = $("#MATERIEL_ID").combobox('getText').toString();
            console.log(MATERIEL_NAME,'MATERIEL_NAME');
            $("#List").datagrid("load", { BATCH_CODE: BATCH_CODE, SAMPLING_BEGIN_TIME: SAMPLING_BEGIN_TIME, SAMPLING_END_TIME: SAMPLING_END_TIME, MATERIEL_NAME: MATERIEL_NAME });
        });

        $("#btnExport").click(function() {

            var BATCH_CODE = $("#BATCH_CODE").val();
            var SAMPLING_BEGIN_TIME = $("#SAMPLING_BEGIN_TIME").val();
            var SAMPLING_END_TIME = $("#SAMPLING_END_TIME").val();
            var MATERIEL_NAME = $("#MATERIEL_ID").combobox('getText').toString();



            $.post("@Url.Action("CheckExportData")?BATCH_CODE=" + BATCH_CODE + "&SAMPLING_BEGIN_TIME=" + SAMPLING_BEGIN_TIME + "&SAMPLING_END_TIME=" + SAMPLING_END_TIME + "&MATERIEL_NAME=" + MATERIEL_NAME, function(data) {
                if (data.type == 1)
                {
                    window.location = "@Url.Action("Export")?BATCH_CODE=" + BATCH_CODE + "&SAMPLING_BEGIN_TIME=" + SAMPLING_BEGIN_TIME + "&SAMPLING_END_TIME=" + SAMPLING_END_TIME + "&MATERIEL_NAME=" + MATERIEL_NAME;
                }
                else
                {
                    $.messageBox5s(Lang.Tip, data.message);
                }
            }, "json");
        });

    });
    function frameReturnByMes(mes) {
        $.messageBox5s(Lang.Tip, mes);
    }

    function resizeLayout()
     {
         setTimeout(function () {
             $('#ListParent').datagrid('resize', {
             }).datagrid('resize', {
                 width: SetGridWidthSub(10),
             });
             $('#List').datagrid('resize', {
             }).datagrid('resize', {
                 width: $(window).width() - 420,
             });
             $("#Before_Img").height(SetGridHeightSub(45));
             $("#After_Img").height(SetGridHeightSub(45));
         },100);
	    }
</script>

